package MIPush.messagefactory;

import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import com.xiaomi.xmpush.server.Message;
import com.xiaomi.xmpush.server.Message.IOSBuilder;

import MIPush.MessageInfo;
import cn.westv.scps.utils.StringUtils;

public class IOSMessageFactory extends MessageFactory {
	protected IOSMessageFactory() {
	}

	@Override
	public Message createMessage(MessageInfo messageInfo) {
		IOSBuilder builder = new IOSBuilder();
		builder.description(messageInfo.getDescription());
		builder.timeToLive(messageInfo.getMilliseconds());
		builder.timeToSend(messageInfo.getTimeToSend());
		String soundURL = messageInfo.getSoundURL();
		if (StringUtils.isNotBlank(soundURL))
			builder.soundURL(soundURL);
		Integer badge = messageInfo.getBadge();
		if (badge != null)
			builder.badge(badge);
		String category = messageInfo.getCategory();
		if (StringUtils.isNotBlank(category))
			builder.category(category);

		Map<String, String> extra = messageInfo.getExtra();
		if (extra != null && extra.size() > 0) {
			Set<Entry<String, String>> entrySet = extra.entrySet();
			for (Entry<String, String> entry : entrySet) {
				builder.extra(entry.getKey(), entry.getValue());
			}
		}
		return builder.build();
	}

}
